package thread;

import java.util.concurrent.*;

public class TestCallable implements Callable<Boolean> {
    @Override
    public Boolean call() throws Exception {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+"开始Callable线程--"+i);
        }
        return true;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //获取继承Callable接口类对象
        TestCallable t1 = new TestCallable();
        //创建执行服务，并规定线程池
        ExecutorService service = Executors.newFixedThreadPool(1);
        //提交执行任务，得到结果池
        Future<Boolean> r1 = service.submit(t1);
        //获取结果池的结果
        boolean rs1 = r1.get();
        System.out.println(rs1);
        //关闭服务
        service.shutdownNow();
    }
}
